package br.com.socket.transmiter;

import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;

public class Cliente extends Thread {

	private String message;
	private int port;

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	public Cliente() {
		setMessage("Iniciado");
	}

	public Cliente(String message, int port) {
		if (message == null) {
			setMessage("No Message");
		}
		this.message = message; 
		this.port = port;
	}
	

	public void run() {
		
		Socket s = null;
		PrintStream ps = null;
		
		try {
			s = new Socket("localhost", port);
			ps = new PrintStream(s.getOutputStream());
			ps.println(getMessage());

		} catch (IOException e) {
			System.err.println("Algum problema ocorreu ao criar ou enviar dados pelo socket.");
		} finally {
			try {
				s.close();
			} catch (IOException e) {
			}
		}
	}
}
